package com.orientsec.autotest.project.system.autoRequest.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.orientsec.autotest.framework.aspectj.lang.annotation.Log;
import com.orientsec.autotest.framework.aspectj.lang.enums.BusinessType;
import com.orientsec.autotest.project.system.autoRequest.domain.AutoRequest;
import com.orientsec.autotest.project.system.autoRequest.service.IAutoRequestService;
import com.orientsec.autotest.framework.web.controller.BaseController;
import com.orientsec.autotest.framework.web.page.TableDataInfo;
import com.orientsec.autotest.framework.web.domain.AjaxResult;
import com.orientsec.autotest.common.utils.poi.ExcelUtil;

/**
 * 请求功能信息操作处理
 * 
 * @author autotest
 * @date 2020-01-15
 */
@Controller
@RequestMapping("/system/autoRequest")
public class AutoRequestController extends BaseController
{
    private String prefix = "system/autoRequest";
	
	@Autowired
	private IAutoRequestService autoRequestService;
	
	@RequiresPermissions("system:autoRequest:view")
	@GetMapping()
	public String autoRequest()
	{
	    return prefix + "/autoRequest";
	}
	
	/**
	 * 查询请求功能列表
	 */
	@RequiresPermissions("system:autoRequest:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(AutoRequest autoRequest)
	{
		startPage();
        List<AutoRequest> list = autoRequestService.selectAutoRequestList(autoRequest);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出请求功能列表
	 */
	@RequiresPermissions("system:autoRequest:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AutoRequest autoRequest)
    {
    	List<AutoRequest> list = autoRequestService.selectAutoRequestList(autoRequest);
        ExcelUtil<AutoRequest> util = new ExcelUtil<AutoRequest>(AutoRequest.class);
        return util.exportExcel(list, "autoRequest");
    }
	
	/**
	 * 新增请求功能
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存请求功能
	 */
	@RequiresPermissions("system:autoRequest:add")
	@Log(title = "请求功能", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(AutoRequest autoRequest)
	{		
		return toAjax(autoRequestService.insertAutoRequest(autoRequest));
	}

	/**
	 * 修改请求功能
	 */
	@GetMapping("/edit/{requestSeqNo}")
	public String edit(@PathVariable("requestSeqNo") String requestSeqNo, ModelMap mmap)
	{
		AutoRequest autoRequest = autoRequestService.selectAutoRequestById(requestSeqNo);
		mmap.put("autoRequest", autoRequest);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存请求功能
	 */
	@RequiresPermissions("system:autoRequest:edit")
	@Log(title = "请求功能", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(AutoRequest autoRequest)
	{		
		return toAjax(autoRequestService.updateAutoRequest(autoRequest));
	}
	
	/**
	 * 删除请求功能
	 */
	@RequiresPermissions("system:autoRequest:remove")
	@Log(title = "请求功能", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(autoRequestService.deleteAutoRequestByIds(ids));
	}
	
}
